package leetcode.code213;

public class Solution1 {

	public static void main(String[] args) {
		int[] nums1 = { 2, 3, 2 };
		int[] nums2 = { 1, 2, 3, 1 };
		int[] nums3 = { 1 };
		Solution1 solution = new Solution1();
		int result = solution.rob(nums3);
//		int result = solution.massage(nums2, 0, nums2.length);
		System.out.println(result);
	}

	public int massage(int[] numssrc, int begin, int size) {
		int[] nums = new int[size];
		for (int i = 0; i < size; i++) {
			nums[i] = numssrc[begin++];
		}
		int len = nums.length;
		if (len == 0)
			return 0;
		if (len == 1)
			return nums[0];
		if (len == 2)
			return Math.max(nums[0], nums[1]);
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		num1 = nums[0];
		num2 = Math.max(nums[0], nums[1]);
		for (int i = 2; i < len; i++) {
			num3 = Math.max(num2, num1 + nums[i]);
			num1 = num2;
			num2 = num3;
		}
		return num2;
	}

	public int rob(int[] nums) {
		int len = nums.length;
		if (len == 0)
			return 0;
		if (len == 1)
			return nums[0];
		if (len == 2)
			return Math.max(nums[0], nums[1]);
		int r1 = this.massage(nums, 0, nums.length - 1);
		int r2 = this.massage(nums, 1, nums.length - 1);
		return Math.max(r1, r2);
	}

}
